﻿var map;
var myLatlng = new google.maps.LatLng(10.8230989 ,106.6296638); // hcm
var currentLatlng;

function initialize()
{
    GetInterviewPosition();
}

function GetInterviewPosition()
{
    request = new XMLHttpRequest();
    request.open("GET", document.forms.frmViewEnrollInformation.action);  // HTTP POST, action Form1
    request.onreadystatechange = interviewPlaceCallBack;              // callback to function callBack
    request.setRequestHeader("ViewInterviewPlaces", "true");  // registry RequestHeader LoadAllPlaces
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    request.send(null);
}

function interviewPlaceCallBack() 
{
    if (request.readyState == 4 && request.status == 200) 
    {
        // xml is sended from server
        var responseXML = request.responseXML;
        var root = responseXML.documentElement;
        
        for (var i = 0; i < root.childNodes.length; i++) 
        {
            // get data detail Place from XML
            var lat = root.childNodes[i].attributes.getNamedItem("Lat").nodeValue;  // lat
            var lng = root.childNodes[i].attributes.getNamedItem("Lng").nodeValue;  // lng
            currentLatlng = new google.maps.LatLng(lat, lng); 
        }
        CreateMap();
    }
}

function CreateMap()
{
    // Options
    var Options = 
    { 
        zoom: 14, 
        center: currentLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    
    // init Map
    map = new google.maps.Map(document.getElementById("map"), Options); 

    // create Marker
    var marker = new google.maps.Marker({ 
    position: currentLatlng,  
    map: map, 
    draggable: true,
    animation: google.maps.Animation.DROP,
    icon: 'Scripts/Images/Cafe.png', 
    title: '.:!rongcon!:.'
    });
    
    // create Inforwindow
    var contentString = "<font size='4px'>Địa Điểm Phỏng Vấn</font>";
    var infowindow = new google.maps.InfoWindow({ 
        content: contentString 
    });
    
    // event click on Marker
    google.maps.event.addListener(marker, "click", function()
    {
        // show information
        infowindow.open(map, marker);
    });
}